package com.tao.poly_.polyarr;

public class PolyArray {
    public static void main(String[] args) {
        Person[] person = new Person[5];
        person[0] = new Person("Tommy",10);
        person[1] = new Student("Smith",11,62.1);
        person[2] = new Student("Davy",12,53);
        person[3] = new Teacher("Jack",13,50000);
        person[4] = new Teacher("Marry",14,22000);
        
        //循环遍历多态数组调用say
        for (int i = 0; i < person.length; i++) {
            System.out.println(person[i].say());
            if(person[i] instanceof Student){
                Student student = (Student)person[i];
                student.study();
            }else if(person[i] instanceof Teacher){
                Teacher teacher = (Teacher)person[i];
                teacher.teach();
            }else if(person[i] instanceof Person){

            }else{
                System.out.println("找不到");
            }
        }
    }
}
